package Login_02;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class Login extends HttpServlet{
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String uname = req.getParameter("userName");
        String pwd = req.getParameter("pwd");
        //遍历注册了的list
        String msg = "账户密码错误";
        resp.setHeader("Content-Type","text/html;charset=UTF-8");//设置utf-8
        for (User user:
             Register.list) {
            if(user.getUname().equals(uname)&&user.getPwd().equals(pwd)){
                msg = "欢迎回来";
                resp.getWriter().write(msg);
                return;
            }
        }
        resp.getWriter().write(msg);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }
}
